package com.finance.cooperate.data.listener;

import com.finance.cooperate.common.utils.SpringContextUtil;
import com.finance.cooperate.data.base.ReaderThreadPool;
import com.finance.cooperate.data.thread.ReaderProcessorThread;
import com.finance.cooperate.data.thread.ReaderQueue;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * @ClassName InitListener
 * @Description 系统初始化监听器
 * @Author shen
 * @Date 2023/8/10 18:05
 * @Modify ...
 */
public class InitListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        //获取spring上下文
        ServletContext sc = sce.getServletContext();
        ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(sc);
        SpringContextUtil.setApplicationContext(context);

        //初始化工作线程池和内存队列
        ReaderQueue.init();
        new Thread(new ReaderProcessorThread()).start();

        ReaderThreadPool.init();
    }

}
